<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>select获取自定义属性值</title>
    <link rel="stylesheet" href="../layui/css/layui.css"/>
</head>
<body class="layui-form">

<input type="checkbox" lay-filter="test" name="test" lay-skin="primary"/>看电视
<input type="checkbox" lay-filter="test" name="test" lay-skin="primary"/>看电影
<input type="checkbox" lay-filter="test" name="test" lay-skin="primary"/>上网
<input type="checkbox" lay-filter="test" name="test" lay-skin="primary"/>爬山
<input type="checkbox" lay-filter="test" name="test" lay-skin="primary"/>游乐场
<input type="checkbox" lay-filter="test" name="test" lay-skin="primary"/>逛街
<input type="checkbox" lay-filter="test" name="test" lay-skin="primary"/>聚会

<script src="../layui/layui.js"></script>
<script>
    //一般直接写在一个js文件中
    layui.use(['layer', 'form', 'jquery'], function () {
        var layer = layui.layer
            , form = layui.form
            , $ = layui.jquery;

        form.on('checkbox(test)',function (data) {
            if ($("input[name='test']:checked").length >= 4) {
                $(data.elem).removeProp('checked'); //或者$(this)
                form.render();
                alert("最多选3个!");
            }
        })
    });
</script>
</body>
</html>